package com.sam.android.callersl;



import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.TextView;

public class CallerSLActivity extends Activity {
    /** Called when the activity is first created. */
	 /** Called when the activity is first created. */
	 private static CallerSLActivity mInst;
	 @SuppressWarnings("unused")
	private double latVal;
	 @SuppressWarnings("unused")
	private double logVal;
	 private LocationManager locmgr = null;
	 private TextView mydebugtv;
	 public void sendMyLocation() {
	    	
		 mydebugtv.setText("sent info");
		 finish();
	    }


	    public static CallerSLActivity instance() {
	              return mInst;
	    }
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
       mydebugtv = (TextView) findViewById(R.id.tvDebugStatus);

       locmgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
       mydebugtv.setText("waiting for location");
       mInst = this;

   }
  

 //Start a location listener
   LocationListener onLocationChange=new LocationListener() {
       public void onLocationChanged(Location loc) {
           //sets and displays the lat/long when a location is provided
           String latlong = "Lat: " + loc.getLatitude() + " Long: " + loc.getLongitude(); 
           latVal = loc.getLatitude();
           logVal = loc.getLongitude();
           mydebugtv.setText(latlong);
       }
        
       public void onProviderDisabled(String provider) {
       // required for interface, not used
       }
        
       public void onProviderEnabled(String provider) {
       // required for interface, not used
       }
        
       public void onStatusChanged(String provider, int status,
       Bundle extras) {
       // required for interface, not used
       }
   };
   
   //pauses listener while app is inactive
   @Override
   public void onPause() {
       super.onPause();
       locmgr.removeUpdates(onLocationChange);
   }
   
   //reactivates listener when app is resumed
   @Override
   public void onResume() {
       super.onResume();
       locmgr.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,10000.0f,onLocationChange);
   }
   
}